/**
 * 产品修改js
 */
var comValidform = null;
var returnStatus = false;
var cardsHistory = {
	curPage : 1,
	pageSize : 10,
	dataCache : null,

	// 设置分页
	setPageChange : function(delCurPage) {
		var url = 'mgr/apiSecretCtrl/list';
		var params = null;
		var cb = function(data) {
			if (data.resultCode == 200) {
				var totalCount = data.size;
				var pageTotal = (totalCount / cardsHistory.pageSize > 0) ? Math
						.ceil(totalCount / cardsHistory.pageSize) : 1;
				pageHelper.init(pageTotal, totalCount, cardsHistory.search,
						delCurPage); // 翻页事件
			}
		};
		sendApiNoLoad(url, params, cb, 'GET');
	},

	// 查询积分规则
	search : function(pageIdx) {
		var url = 'mgr/apiSecretCtrl/list';
		var params = null;
		if (typeof (pageIdx) != "undefined") {
			cardsHistory.curPage = pageIdx;
		}

		var cb = function(data) {
			$('#tableList tbody').empty();
			var tr = '';
			if (data.resultCode == 200 && data.result != null
					&& data.result.length > 0) {
				for (var i = 0; i < data.result.length; i++) {
					var singleObj = data.result[i];
					localStorage.setItem(singleObj.id + "_ApiSecret_Key", JSON
							.stringify(singleObj));

					tr += '<tr><td>' + (i + 1) + '</td><td>' + singleObj.name
							+ '</td><td>' + singleObj.apikey + '</td><td>'
							+ singleObj.apiSecret + '</td><td>'
							+ singleObj.type + '</td><td>' + singleObj.channel
							+ '</td></tr>';
				}
			} else {
				tr = '<tr><td colspan="7" style="text-align: center;color: red;">暂无数据</td></tr>';
			}
			$('#tableList tbody').html(tr);
			jsUtils.controlFunctionBtn();

		};
		sendApiNoLoad(url, params, cb, 'GET');
	},

	bindEvent : function() {
		// 查询
		$('#addData').on('click', function() {
			var thisObj = $(this);
			var url = 'mgr/apiSecretCtrl/add';
			var params = jsUtils.serializeJson($('.com-addForm'));
			var cb = function(data) {
				alert(data.msg);

			};
			sendApiNoLoadSync(url, params, cb, 'POST');
		});

	},

	init : function() {
		cardsHistory.setPageChange(null);
		cardsHistory.search();
		cardsHistory.bindEvent();
	}
}
$(document).ready(function() {
	cardsHistory.init();
});
function submitForm() {
	comValidform.submitForm();
	return returnStatus;
}